﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.IO;

namespace Core
{
    public class AppUtil
    {
        public static Image ResizeImage(Image srcImage, int iWidth, int iHeight)
        {
            Bitmap newImage = new Bitmap(iWidth, iHeight);
            using (Graphics gr = Graphics.FromImage(newImage))
            {
                gr.SmoothingMode = SmoothingMode.HighQuality;
                gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
                gr.DrawImage(srcImage, new Rectangle(0, 0, iWidth, iHeight));
            }

            return newImage;
        }

        public static Image GetImageFromFileName(String path, String strFileName)
        {
            Image img = null;

            String[] fileNameList = Directory.GetFiles(path, String.Format("{0}*", strFileName), SearchOption.AllDirectories);
            if (fileNameList.Length > 0)
                return Image.FromFile(fileNameList[0]);

            return img;
        }

        public static Image GetImageFromFileName(String path, String strFileName, int iWidth, int iHeight)
        {
            

            Image scrImg = GetImageFromFileName(path, strFileName);

            return ResizeImage(scrImg, iWidth, iHeight);
        }
    }
}
